package com.neusoft.yuejian_01.model;

import com.neusoft.yuejian_01.base.BaseModel;
import com.neusoft.yuejian_01.javabean.IsTrainReg;
import com.neusoft.yuejian_01.javabean.NoRegBean;
import com.neusoft.yuejian_01.javabean.TrainBean;
import com.neusoft.yuejian_01.javabean.TrainRegBean;
import com.neusoft.yuejian_01.listener.RetrofitListener;
import com.neusoft.yuejian_01.service.TrainService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Administrator on 2017/10/2.
 */

public class TrainModel extends BaseModel {

    //全部培训列表
    public void trainlist(final RetrofitListener listener){
        this.flag = Const.TrainList;
        TrainService trainService = retrofit.create(TrainService.class);
        Call<List<TrainBean>> call = trainService.getTrainlist();
        Callback<List<TrainBean>> callback = new Callback<List<TrainBean>>() {
            @Override
            public void onResponse(Call<List<TrainBean>> call, Response<List<TrainBean>> response) {
                List<TrainBean> trainBean = response.body();
                listener.onSuccess(trainBean,flag);
            }
            @Override
            public void onFailure(Call<List<TrainBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }
    //培训入门列表
    public void trainrlist(final RetrofitListener listener){
        this.flag = Const.TrainRList;
        TrainService trainService = retrofit.create(TrainService.class);
        Call<List<TrainBean>> call = trainService.getTrainRTypelist();
        Callback<List<TrainBean>> callback = new Callback<List<TrainBean>>() {
            @Override
            public void onResponse(Call<List<TrainBean>> call, Response<List<TrainBean>> response) {
                List<TrainBean> trainBean = response.body();
                listener.onSuccess(trainBean,flag);
            }
            @Override
            public void onFailure(Call<List<TrainBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }
    //培训进阶列表
    public void trainjlist(final RetrofitListener listener){
        this.flag = Const.TrainJList;
        TrainService trainService = retrofit.create(TrainService.class);
        Call<List<TrainBean>> call = trainService.getTrainJTypelist();
        Callback<List<TrainBean>> callback = new Callback<List<TrainBean>>() {
            @Override
            public void onResponse(Call<List<TrainBean>> call, Response<List<TrainBean>> response) {
                List<TrainBean> trainBean = response.body();
                listener.onSuccess(trainBean,flag);
            }
            @Override
            public void onFailure(Call<List<TrainBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }
    //培训高级列表
    public void trainglist(final RetrofitListener listener){
        this.flag = Const.TrainGList;
        TrainService trainService = retrofit.create(TrainService.class);
        Call<List<TrainBean>> call = trainService.getTrainGTypelist();
        Callback<List<TrainBean>> callback = new Callback<List<TrainBean>>() {
            @Override
            public void onResponse(Call<List<TrainBean>> call, Response<List<TrainBean>> response) {
                List<TrainBean> trainBean = response.body();
                listener.onSuccess(trainBean,flag);
            }
            @Override
            public void onFailure(Call<List<TrainBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }
    //培训详情
    public void traindetail(String t_id,final RetrofitListener listener){
        this.flag = Const.TrainDeatl;
        TrainService trainService = retrofit.create(TrainService.class);
        Call call = trainService.getTraindetail(t_id);
        call.enqueue(new Callback<TrainBean>() {
            @Override
            public void onResponse(Call<TrainBean> call, Response<TrainBean> response) {
                TrainBean traindetail=response.body();
                listener.onSuccess(traindetail,flag);
            }
            @Override
            public void onFailure(Call<TrainBean> call, Throwable t)  {
                listener.onFail();
            }
        });
            }
            //培训报名
    public void trainreg(String u_id,String t_id,final RetrofitListener listener){
        this.flag = Const.TrainReg;
        TrainService trainService = retrofit.create(TrainService.class);
        Call call = trainService.addTrainRegistration(u_id,t_id);
        call.enqueue(new Callback<TrainRegBean>() {
            @Override
            public void onResponse(Call<TrainRegBean> call, Response<TrainRegBean> response) {
                TrainRegBean trainRegBean=response.body();
                listener.onSuccess(trainRegBean,flag);
            }
            @Override
            public void onFailure(Call<TrainRegBean> call, Throwable t)  {
                listener.onFail();
            }
        });
    }
    //搜素培训
    public void search(String t_name,final RetrofitListener listener){
        this.flag = Const.TrainList;
        TrainService trainService = retrofit.create(TrainService.class);
        Call<List<TrainBean>> call = trainService.getTrainSearchlist(t_name);
        Callback<List<TrainBean>> callback = new Callback<List<TrainBean>>() {
            @Override
            public void onResponse(Call<List<TrainBean>> call, Response<List<TrainBean>> response) {
                List<TrainBean> trainBean = response.body();
                listener.onSuccess(trainBean,flag);
            }
            @Override
            public void onFailure(Call<List<TrainBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }
    //判断报名
    public void getIsReg(String u_id, String t_id,final RetrofitListener listener) {
        this.flag = Const.IsTrainReg;
        TrainService trainService = retrofit.create(TrainService.class);
        Call call = trainService.getIsReg(u_id,t_id);
        call.enqueue(new Callback<IsTrainReg>() {
            @Override
            public void onResponse(Call<IsTrainReg> call, Response<IsTrainReg> response) {
                IsTrainReg isTrainReg=response.body();
                listener.onSuccess(isTrainReg,flag);
            }
            @Override
            public void onFailure(Call<IsTrainReg> call, Throwable t) {
                listener.onFail();
            }
        });
    }
    //取消报名
    public void getIsNotReg(String u_id, String t_id,final RetrofitListener listener) {
        this.flag = Const.NoReg;
        TrainService trainService = retrofit.create(TrainService.class);
        Call call = trainService.getIsNotReg(u_id,t_id);
        call.enqueue(new Callback<NoRegBean>() {
            @Override
            public void onResponse(Call<NoRegBean> call, Response<NoRegBean> response) {
                NoRegBean noRegBean=response.body();
                listener.onSuccess(noRegBean,flag);
            }
            @Override
            public void onFailure(Call<NoRegBean> call, Throwable t) {
                listener.onFail();
            }
        });
    }
    //培训报名订单
    public void getTrainRegistration(String u_id,String t_id,final RetrofitListener listener){
        this.flag = Const.TrainOrder;
        TrainService trainService = retrofit.create(TrainService.class);
        Call call = trainService.getTrainRegistration(u_id,t_id);
        call.enqueue(new Callback<TrainRegBean>() {
            @Override
            public void onResponse(Call<TrainRegBean> call, Response<TrainRegBean> response) {
                TrainRegBean trainRegBean=response.body();
                listener.onSuccess(trainRegBean,flag);
            }
            @Override
            public void onFailure(Call<TrainRegBean> call, Throwable t)  {listener.onFail();
            }
        });
    }
}
